/**
 *
 */

package com.moogene.android.engine.mmi.widget;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

import com.moogene.android.InfoMediator;
import com.moogene.android.R;
import com.moogene.android.engine.font.Latin;

/**
 * @author 28850924
 * 
 */
public class Button extends Widget {

	private Drawable[] mStateImgs = new Drawable[2];

	String mText = "";

	/**
	 * @param top
	 * @param left
	 * @param width
	 * @param height
	 */
	public Button(int x, int y, int width, int height) {
		super(x, y, width, height);
		setStateImages(InfoMediator.getDrawable(R.drawable.btn_custom_normal),
				InfoMediator.getDrawable(R.drawable.btn_custom_pressed));
	}

	public void setStateImages(Drawable normal, Drawable pressed) {
		mStateImgs[0] = normal;
		mStateImgs[1] = pressed;
	}

	public void setText(String text) {
		mText = text;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.moogene.android.engine.mmi.Layer#draw(android.graphics.Canvas)
	 */
	@Override
	protected void onDraw(Canvas canvas) {
		if (isHold()) {
			mStateImgs[1].setBounds(getDstRect());
			mStateImgs[1].draw(canvas);
		} else {
			mStateImgs[0].setBounds(getDstRect());
			mStateImgs[0].draw(canvas);
		}
		Rect r = new Rect(getDstRect());
		r.inset((r.width() - Latin.getInstance().getTextWidth(mText,
				Latin.FONT1)) >> 1, (r.height() - Latin.getInstance()
				.getMaxHeight(Latin.FONT1)) >> 1);
		Latin.getInstance().drawText(canvas, Latin.FONT1, mText, r);
	}
}
